<template>
	<view class="content" >
		<swiper  :autoplay="false" @change="swiperChange" class="swiper_view" :current="swiperCurrent" :circular='circular' :display-multiple-items="1" next-margin="250rpx" previous-margin="250rpx">
			<swiper-item v-for="(item,index) in list" :key="index" class="swiper_item flex-c-c">
				<view class="text"  @click="scrollTo(index,null)">{{item.name}}</view>
				<view class="back_view"  @click="scrollTo(index,null)" v-if="swiperCurrent == index" style="background: url(https://pd.pdaxiang.com/upload/static/index/scorwbj.png);">
				</view>
				<view class="back_view"  @click="scrollTo(index,null)" v-else style="background: url(https://pd.pdaxiang.com/upload/static/index/scorwbjs.png);">
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				swiperCurrent:0,
				circular:true,
				currentIndex: 0,
			}
		},
		props: {
			list: {
				type: Array
			}
		},
		methods: {
			swiperChange(e){
				this.swiperCurrent = e.detail.current
				let num = this.list.length
				if (this.swiperCurrent >= num) {
					this.swiperCurrent = 0
				}
				this.$emit('switchChange',{swiperCurrent:this.swiperCurrent})
			},
			async scrollTo(index){
				if(this.swiperCurrent != index){
					this.circular = true
					this.swiperCurrent = index
					if(this.swiperCurrent+1 == index){
					}else{
					}
				}
				this.$emit('switchChange',{swiperCurrent:this.swiperCurrent})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.back_view{
		width: 190rpx;
		height: 70rpx;
		line-height: 70rpx;
		color: #fff;
		background-repeat: no-repeat !important;
		background-size: 100% 100% !important;
		position: absolute;
		margin:auto;
		left:0;
		right:0;
		z-index: -1;
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	.swiper_view{
		width: 750rpx;
		height: 88rpx;
	}
	.swiper_item{
		 height: 88rpx;
		  .text{
			  font-size: 34rpx;
			  font-family: PingFang SC;
			  font-weight: 500;
			  color: #FFFFFF;
		  }
	}
	
	.content {
		height: 102rpx;

		.list {
			white-space: nowrap;
			height: 102rpx;
			line-height: 102rpx;
			.item {
				display: inline-block;

				height: 170rpx;
				line-height: 170rpx;
				border-radius: 10rpx;
				position: relative;
				vertical-align: middle;

				.img {
					margin: 0 auto;
					width: 110rpx;
					height: 110rpx;
					max-width: 110rpx;
					max-height: 110rpx;
					min-width: 110rpx;
					min-height: 110rpx;
					background-size: 110rpx;
					background-repeat: no-repeat;
					background-position: 0;
				}

				.text {
					width: 640rpx;
					min-height: 70rpx;
					text-align: center;
					font-size: 34rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					letter-spacing: 3rpx;
					line-height: 70rpx;
				}
				
			}
		}
	}
</style>
